package com.zhisheng.controller;

import com.zhisheng.Dto.EmpDto;
import com.zhisheng.pojo.Emp;
import com.zhisheng.pojo.MyResponseResult;
import com.zhisheng.pojo.PageBean;
import com.zhisheng.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 员工管理Controller
 */
@RestController
@RequestMapping("/emps")
public class EmpController {
    @Autowired
    private EmpService empService;
    @GetMapping
    /*
      @RequestParam作用：防止参数传递错误，设置默认值
    */
    public MyResponseResult getByPage(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "4") Integer pageSize, EmpDto empDto) {

        PageBean<Emp> pageBean = empService.getByPage(page, pageSize,empDto);
        return MyResponseResult.ok(pageBean);
    }
    @DeleteMapping("/{id}")
    public MyResponseResult<Object> deByIds(@PathVariable Integer ids) {
        int i = empService.deByIds(ids);
        return i>1?MyResponseResult.ok("null"):MyResponseResult.error("删除失败");
    }
}
